"rustc-serialize 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"tar 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tempdir 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
"threadpool 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
+[[package]]
+name = "rand"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "regex"
version = "0.1.18"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
+[[package]]
+name = "tempdir"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rand 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "term"
version = "0.1.13"
regex = "0.1.18"
threadpool = "0.1.1"
libc = "0.1.2"
+registry = { path = "src/registry" }
-[target.i686-pc-windows-gnu.dependencies]
-winapi = "0.1"
-advapi32-sys = "*"
+[target.i686-pc-windows-gnu]
+dependencies = { winapi = "0.1", advapi32-sys = "*" }
+[target.x86_64-pc-windows-gnu]
+dependencies = { winapi = "0.1", advapi32-sys = "*" }
-[target.x86_64-pc-windows-gnu.dependencies]
-winapi = "0.1"
-advapi32-sys = "*"
-
-[dev-dependencies.hamcrest]
-git = "https://github.com/carllerche/hamcrest-rust.git"
-
-[dependencies.registry]
-path = "src/registry"
+[dev-dependencies]
+tempdir = "0.3"
+hamcrest = { git = "https://github.com/carllerche/hamcrest-rust.git" }
[[bin]]
name = "cargo"
[[test]]
name = "tests"
-[[bench]]
-name = "tests"
-path = "tests/tests.rs"
[[test]]
name = "resolve"
return Ok(None)
}
- let (mut args, command) = match &flags.arg_command[..] {
+ let args = match &flags.arg_command[..] {
+ // For the commands `cargo` and `cargo help`, re-execute ourselves as
+ // `cargo -h` so we can go through the normal process of printing the
+ // help message.
"" | "help" if flags.arg_args.len() == 0 => {
config.shell().set_verbose(true);
- let args = &["foo".to_string(), "-h".to_string()];
+ let args = &["cargo".to_string(), "-h".to_string()];
let r = cargo::call_main_without_stdin(execute, config, USAGE, args,
false);
- cargo::process_executed(r, &mut **config.shell());
+ cargo::process_executed(r, &mut config.shell());
return Ok(None)
}
+
+ // For `cargo help -h` and `cargo help --help`, print out the help
+ // message for `cargo help`
"help" if flags.arg_args[0] == "-h" ||
- flags.arg_args[0] == "--help" =>
- (flags.arg_args, "help"),
- "help" => (vec!["-h".to_string()], &flags.arg_args[0][..]),
- s => (flags.arg_args.clone(), s),
+ flags.arg_args[0] == "--help" => {
+ vec!["cargo".to_string(), "help".to_string(), "help".to_string()]
+ }
+
+ // For `cargo help foo`, print out the usage message for the specified
+ // subcommand by executing the command with the `-h` flag.
+ "help" => {
+ vec!["cargo".to_string(), "help".to_string(),
+ flags.arg_args[0].clone()]
+ }
+
+ // For all other invocations, we're of the form `cargo foo args...`. We
+ // use the exact environment arguments to preserve tokens like `--` for
+ // example.
+ _ => env::args().collect(),
};
- args.insert(0, command.to_string());
- args.insert(0, "foo".to_string());
macro_rules! cmd{ ($name:ident) => (
- if command == stringify!($name).replace("_", "-") {
+ if args[1] == stringify!($name).replace("_", "-") {
mod $name;
config.shell().set_verbose(true);
let r = cargo::call_main_without_stdin($name::execute, config,
$name::USAGE,
&args,
false);
- cargo::process_executed(r, &mut **config.shell());
+ cargo::process_executed(r, &mut config.shell());
return Ok(None)
}
) }
each_subcommand!(cmd);
- execute_subcommand(&command, &args, &mut config.shell());
+ execute_subcommand(&args[1], &args, &mut config.shell());
Ok(None)
}
}
#[cfg(windows)]
fn is_executable(path: &Path) -> bool {
- path.is_file()
+ fs::metadata(path).map(|m| m.is_file()) == Ok(true)
}
/// Get `Command` to run given command.
use std::env;
use std::fs;
use std::io::prelude::*;
-use std::io;
+use std::io::{self, ErrorKind};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
*/
fn rm_rf(&self) -> io::Result<()> {
if self.exists() {
- fs::remove_dir_all(self)
+ for file in fs::read_dir(self).unwrap() {
+ let file = try!(file).path();
+
+ if file.is_dir() {
+ try!(file.rm_rf());
+ } else {
+ // On windows we can't remove a readonly file, and git will
+ // often clone files as readonly. As a result, we have some
+ // special logic to remove readonly files on windows.
+ match fs::remove_file(&file) {
+ Ok(()) => {}
+ Err(ref e) if cfg!(windows) &&
+ e.kind() == ErrorKind::PermissionDenied => {
+ let mut p = file.metadata().unwrap().permissions();
+ p.set_readonly(false);
+ fs::set_permissions(&file, p).unwrap();
+ try!(fs::remove_file(&file));
+ }
+ Err(e) => return Err(e)
+ }
+ }
+ }
+ fs::remove_dir(self)
} else {
Ok(())
}
let file = match name.len() {
1 => format!("1/{}", name),
2 => format!("2/{}", name),
- 3 => format!("3/{}/{}", name.slice_to(1), name),
- _ => format!("{}/{}/{}", name.slice(0, 2), name.slice(2, 4), name),
+ 3 => format!("3/{}/{}", &name[..1], name),
+ _ => format!("{}/{}/{}", &name[0..2], &name[2..4], name),
};
publish(file.as_slice(), line.as_slice());
}
use std::collections::HashSet;
-use std::old_io::net::tcp::TcpAcceptor;
-use std::old_io::{TcpListener, Listener, Acceptor, BufferedStream};
+use std::io::BufStream;
+use std::io::prelude::*;
+use std::net::TcpListener;
use std::thread;
use git2;
fn setup() {
}
-struct Closer { a: TcpAcceptor }
-
-impl Drop for Closer {
- fn drop(&mut self) {
- let _ = self.a.close_accept();
- }
-}
-
// Test that HTTP auth is offered from `credential.helper`
test!(http_auth_offered {
- let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
- let addr = listener.socket_name().unwrap();
- let mut a = listener.listen().unwrap();
- let a2 = a.clone();
- let _c = Closer { a: a2 };
+ let a = TcpListener::bind("127.0.0.1:0").unwrap();
+ let addr = a.socket_addr().unwrap();
- fn headers<R: Buffer>(rdr: &mut R) -> HashSet<String> {
+ fn headers(rdr: &mut BufRead) -> HashSet<String> {
let valid = ["GET", "Authorization", "Accept", "User-Agent"];
rdr.lines().map(|s| s.unwrap())
.take_while(|s| s.len() > 2)
}
let t = thread::spawn(move|| {
- let mut s = BufferedStream::new(a.accept().unwrap());
+ let mut s = BufStream::new(a.accept().unwrap().0);
let req = headers(&mut s);
s.write_all(b"\
HTTP/1.1 401 Unauthorized\r\n\
].into_iter().map(|s| s.to_string()).collect());
drop(s);
- let mut s = BufferedStream::new(a.accept().unwrap());
+ let mut s = BufStream::new(a.accept().unwrap().0);
let req = headers(&mut s);
s.write_all(b"\
HTTP/1.1 401 Unauthorized\r\n\
script.display().to_string().as_slice()).unwrap();
let p = project("foo")
- .file("Cargo.toml", format!(r#"
+ .file("Cargo.toml", &format!(r#"
[project]
name = "foo"
version = "0.0.1"
[dependencies.bar]
git = "http://127.0.0.1:{}/foo/bar"
- "#, addr.port).as_slice())
+ "#, addr.port()))
.file("src/main.rs", "");
assert_that(p.cargo_process("build").arg("-v"),
// Boy, sure would be nice to have a TLS implementation in rust!
test!(https_something_happens {
- let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
- let addr = listener.socket_name().unwrap();
- let mut a = listener.listen().unwrap();
- let a2 = a.clone();
- let _c = Closer { a: a2 };
+ let a = TcpListener::bind("127.0.0.1:0").unwrap();
+ let addr = a.socket_addr().unwrap();
let t = thread::spawn(move|| {
drop(a.accept().unwrap());
});
let p = project("foo")
- .file("Cargo.toml", format!(r#"
+ .file("Cargo.toml", &format!(r#"
[project]
name = "foo"
version = "0.0.1"
[dependencies.bar]
git = "https://127.0.0.1:{}/foo/bar"
- "#, addr.port).as_slice())
+ "#, addr.port()))
.file("src/main.rs", "");
assert_that(p.cargo_process("build").arg("-v"),
// Boy, sure would be nice to have an SSH implementation in rust!
test!(ssh_something_happens {
- let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
- let addr = listener.socket_name().unwrap();
- let mut a = listener.listen().unwrap();
- let a2 = a.clone();
- let _c = Closer { a: a2 };
+ let a = TcpListener::bind("127.0.0.1:0").unwrap();
+ let addr = a.socket_addr().unwrap();
let t = thread::spawn(move|| {
drop(a.accept().unwrap());
});
[dependencies.bar]
git = "ssh://127.0.0.1:{}/foo/bar"
- "#, addr.port).as_slice())
+ "#, addr.port()).as_slice())
.file("src/main.rs", "");
assert_that(p.cargo_process("build").arg("-v"),
use std::env;
-use std::fs::{self, TempDir, File};
+use std::fs::{self, File};
use std::io::prelude::*;
+use tempdir::TempDir;
use support::{project, execs, main_file, basic_bin_manifest};
use support::{COMPILING, RUNNING, ProjectBuilder};
use rustc::plugin::Registry;
use syntax::ast::TokenTree;
use syntax::codemap::Span;
- use syntax::ext::base::{ExtCtxt, MacExpr, MacResult};
+ use syntax::ext::base::{ExtCtxt, MacEager, MacResult};
#[plugin_registrar]
pub fn foo(reg: &mut Registry) {
fn expand_bar(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
-> Box<MacResult + 'static> {
- MacExpr::new(quote_expr!(cx, 1))
+ MacEager::expr(quote_expr!(cx, 1))
}
"#);
let baz = project("baz")
use rustc::plugin::Registry;
use syntax::ast::TokenTree;
use syntax::codemap::Span;
- use syntax::ext::base::{ExtCtxt, MacExpr, MacResult};
+ use syntax::ext::base::{ExtCtxt, MacEager, MacResult};
#[plugin_registrar]
pub fn foo(reg: &mut Registry) {
fn expand_bar(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
-> Box<MacResult + 'static> {
- MacExpr::new(quote_expr!(cx, baz::baz()))
+ MacEager::expr(quote_expr!(cx, baz::baz()))
}
"#);
let baz = project("baz")
-use std::fs::{self, File, TempDir};
+use std::fs::{self, File};
use std::io::prelude::*;
use std::env;
+use tempdir::TempDir;
use support::{execs, paths, cargo_dir};
use hamcrest::{assert_that, existing_file, existing_dir, is_not};
execs().with_status(0));
p.root().move_into_the_past().unwrap();
- fs::remove_dir_all(&paths::home().join(".cargo/registry")).unwrap();
+ paths::home().join(".cargo/registry").rm_rf().unwrap();
assert_that(p.cargo("build"),
execs().with_status(0).with_stdout(format!("\
{updating} registry `[..]`
r::mock_pkg("bar", "0.0.2", &[]);
r::mock_pkg("bar", "0.0.3", &[]);
- fs::remove_dir_all(&paths::home().join(".cargo/registry")).unwrap();
+ paths::home().join(".cargo/registry").rm_rf().unwrap();
println!("0.0.2 update");
assert_that(p.cargo("update")
.arg("-p").arg("bar").arg("--precise").arg("0.0.2"),
-#![feature(core, io, old_io, os, old_path)]
-#![feature(std_misc, io, path, fs, tempdir)]
+#![feature(core, io, old_io, old_path)]
+#![feature(std_misc, io, path, fs, net, path_ext, fs_time, fs_walk)]
extern crate "rustc-serialize" as serialize;
extern crate cargo;
extern crate tar;
extern crate term;
extern crate url;
+extern crate tempdir;
#[macro_use]
extern crate log;